<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>存储事件</title>
</head>
<body>
  <button id="btn">点我设置值</button>

  <script>
    const btn = document.querySelector('#btn');
    // 要再打开新页面才会触发
    window.addEventListener('storage', event => {
      console.log(event.domain);
      console.log(event.key);
      console.log(event.newValue);
      console.log(event.oldValue);
    });
    btn.addEventListener('click', () => {
      let count = localStorage.getItem('count');
      count = Number(count || 0);
      localStorage.setItem('count', ++count);
    });
  </script>
</body>
</html>